/**
 * @author xuyunzhou
 */
define(["app"], function(app) {
	
	var deps = ["$parse", "$timeout"];
	
	function directive($parse, $timeout) {
		
		return {
			restrict : "A",
			link : function($scope, element, attrs) {
				var fileInput = $("<input type='file' class='fc-common-upload-btn' multiple>");
				fileInput.insertAfter(element);
				
				fileInput.bind("change", function(){
					var input = this;
					var files = [];
					
					for(var i=0; i<input.files.length; i++) {
						files.push(input.files[i]);
					}

					$timeout(function(){
						$parse(attrs.fcFileInput).assign($scope, files);
					});
				});
			}
		};
	}

	directive.$inject = deps;
	app.lazy.directive("fcFileInput", directive);
});